<?php
/**
 * 教室信息类
 */
namespace app\admin\controller;

use think\App;
use think\facade\View;

class Courseware extends Content
{

    public function __construct(App $app)
    {
        parent::__construct($app);
    }

    public function index()
    {
        parent::index();
        if($this->request->request('check')){
            if($this->request->request('ids'))  View::assign(['ids'=>$this->request->request('ids')]);
            return view('content/checkindex');
        }else{
            return view('content/index');
        }
    }

    public function add(){
        $showData = parent::add();
        if($this->id){
            $showData['id'] = $this->id;
            $showData['detail'] = $this->localModel->findDetaiById('*', $this->id);
            $showData['detail']['tags'] = explode(',', $showData['detail']['tags']);
            $showData['scfData'] = $this->cfmodel->findAllInfo('id, name', [['status', '=', 1], ['level', '=', 2], ['fid', '=', $showData['detail']['cid']]]);
            View::assign($showData);
            return view('content/edit');
        }else{
            View::assign($showData);
            return view('content/add');
        }
    }

    public function save(){
        $this->type = 5;
        $this->validateType = 'file';
        return parent::save();
    }

    public function ajaxGetCourseList(){
        $ctype = $this->request->request('ctype');
        $cid = $this->request->request('cid');

        if(!$ctype || !$cid)  return false;

        $list = $this->localModel->findCourseListBycid($cid, $ctype);

        if(!$list)  return json(['result'=>'fail']);
        return json(['result'=>'success', 'date'=>$list]);
    }

    public function ajaxGetContentList(){
        $cid = $this->request->request('cid');
        $type = $this->request->request('type') ? $this->request->request('type') : 1;

        if(!$cid)  return false;

        $list = $this->localModel->findAllInfo("id, title", [['status', '=', 1], ['examine_status', '=', 9], ['type', '=', $type], ['cid', '=', $cid]]);

        if(!$list)  return json(['result'=>'fail']);
        return json(['result'=>'success', 'date'=>$list]);
    }

}
